<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="csrf-token" content="{{csrf_token()}}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />

    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/font.css')}}">
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/css/xadmin.css')}}">
    <link rel="stylesheet" href="{{URL::asset('resources/xadmin/lib/layui/css/layui.css')}}">

    <script src="{{URL::asset('resources/xadmin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{URL::asset('resources/xadmin/js/xadmin.js')}}"></script>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">



<form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
</form>


<div style="display:none" id="userBar">
       <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe609;</i>分配</a>
       <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
</div>

<div style="display:none" id="hear_bar">
     <button class="layui-btn layui-btn-danger" lay-event="delall"><i class="layui-icon"></i>批量删除</button>
     <button class="layui-btn" lay-event="add" ><i class="layui-icon"></i>添加</button>
</div>


<table class="layui-table" lay-data="{
    url:'{{URL::action('Admin\RoleController@lst')}}', page:false, id:'role_table',toolbar:'#hear_bar'
    }" lay-filter="role_table">
  <thead>
    <tr>
      <th lay-data="{field:'id', width:100, type:'checkbox'}"></th>
      <th lay-data="{field:'id', width:100, sort: true}">角色ID</th>
      <th lay-data="{field:'role_name',width:150}">角色名称</th>
      <th lay-data="{field:'auth_ids', sort: true}">权限ID集合</th>
      <th lay-data="{field:'auth_ac'}">权限AC集合</th>
      <th lay-data="{fixed: 'right', width:200, title:'操作', toolbar: '#userBar', align:'center'}">方法</th>
    </tr>
  </thead>
</table>

<!-- <th lay-data="{field:'pid',templet:function(d){
          if(d.pid=='0')return 'N/A'
          else return 
          }}">父级权限</th> -->

</body>
</div>
</div>
</div>
</div>
</div>
<script>
    

       




    layui.use(['form','layer','table','jquery'],function(){
        var form =layui.form;
        table=layui.table;
        $=layui.jquery;

        //监听工具条
    table.on('tool(role_table)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
        // 获取所在行的id
        // console.log(data['id'])
      //  console.log(obj);
        if(layEvent === 'del'){ //删除
            
            layer.confirm('真的删除吗？',{
                icon:3,
                skin: 'layer-ext-moon',
                btn: ['确认','返回'], //按钮
            },function(){
                $.ajax({
                    url:'{{URL::action('Admin\RoleController@del')}}',
                    type:'post',
                    data:{del_id:data['id'],del_num:'one'},
                    headers : {
                    'X-CSRF-TOKEN' : $("meta[name='csrf-token']").attr('content')
                    },
                    beforeSend:function () {
                        this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
                    },
                    success:function(data){
                        if(data.status=='error'){
                            layer.msg('Error',{
                                icon:5//失败的表情
                                ,time:1000
                            })
                            //return ;
                        }else{
                            layer.msg('Successful Delete!',{
                                icon:6,//成功的表情
                                time:1000
                            },function(){
                               // location.reload();
                               obj.del();
                               
                            });
                        }
                    },
                    complete:function(){
                        layer.close(this.layerIndex);
                    }
                })
            })
            
        }else if(layEvent==='edit'){
            
        console.log(data['id'])
        console.log(obj);
        var edit_id=data['id']

            var curWwwPath = window.document.location.href;
            var pathname= window.document.location.pathname;
            var pos = curWwwPath.indexOf(pathname);
            var localhostPath = curWwwPath .substring(0,pos);
           // layer.alert(localhostPath)

            var URL=localhostPath+'/lhlsite/laravel/public/admin/role/edit/'+edit_id
            console.log(URL)
            //xadmin.open('分配权限','{{url('admin/role/edit')}}',700,500)
            xadmin.open('分配权限',URL,700,500)
        }
        
    });

    table.on("toolbar(role_table)",function(obj){
        var checkStatus = table.checkStatus('role_table')
        
        switch(obj.event){
            case 'add':
            //layer.msg('add');
            xadmin.open('添加用户','{{url('admin/role/add')}}',700,500)
            break;
            case 'delall':
            //layer.msg('delall');console.log(checkStatus.data);console.log(checkStatus.data.length)
                var ids = [];
                num=checkStatus.data.length
                if (num != 0) {

                            for (var i = 0; i < num; i++) {
                            ids.push(checkStatus.data[i].id)
                        }
                        layer.confirm('真的删除吗？',{
                            icon:3,
                            skin: 'layer-ext-moon',
                            btn: ['确认','返回'], //按钮
                        },function(){

                    $.ajax({
                        url: '{{URL::action('Admin\RoleController@del')}}'
                        ,type: 'post'
                        ,headers : {
                            'X-CSRF-TOKEN' : $("meta[name='csrf-token']").attr('content')
                        }
                        ,data:{del_id:ids,del_num:'several'}
                        , success: function (data) {
                            if(data.status=='ok'){                                
                                layer.msg("删除了" +data.nums+"条数据",{
                                icon:6,//成功的表情
                                time:1000
                            },function(){
                                
                               //obj.del();
                               $(".layui-form-checked").not('.header').parents('tr').remove();

                            });
                                
                            }else{
                                layer.msg('Error',{
                                icon:5//失败的表情
                                ,time:1000
                                })
                            }
                           
                        }
                    })

                        })
                }
                else {
                    layer.msg("至少选择一个！")
                }
                //break;
            break;
            
        }
    });

    });
 
</script>

</html>